package com.yan.kfgl.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.yan.kfgl.model.MNUser;
import com.yan.kfgl.model.vo.ShownUser;

public class MNUtil {
	/**
	 * 将MNUser转换为ShownUser
	 * @param user
	 * @return
	 */
	public static ShownUser parseMNUserToShownUser(MNUser user){
		ShownUser su = new ShownUser();
		if(user != null){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			if(user.getName()!=null){
				su.setName(user.getName());
			}else{
				su.setName("");
			}
			if(user.getInsertTimeForHis()!=null){
				su.setInsertTimeForHis(sdf.format(user.getInsertTimeForHis()));
			}else{
				su.setInsertTimeForHis("");
			}
			if(user.getUpdateTimeForHis()!=null){
				su.setUpdateTimeForHis(sdf.format(user.getUpdateTimeForHis()));
			}else{
				su.setUpdateTimeForHis("");
			}
		}
		return su;
	}
	
	/**
	 * 将ShownUser转换位MNUser
	 * @param su ShownUser
	 * @param password 密码
	 * @return
	 */
	public static MNUser formatShownUserToMNUser(ShownUser su , String password){
		MNUser mu = new MNUser();
		mu.setName(su.getName());
		if(password != null && !"".equals(password.trim())){
			mu.setPassword(password);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		if(su.getInsertTimeForHis() != null && !"".equals(su.getInsertTimeForHis().trim())){
			try {
				mu.setInsertTimeForHis(sdf.parse(su.getInsertTimeForHis()));
			} catch (ParseException e) {
			}
		}
		if(su.getUpdateTimeForHis() != null && !"".equals(su.getUpdateTimeForHis().trim())){
			try {
				mu.setUpdateTimeForHis(sdf.parse(su.getUpdateTimeForHis()));
			} catch (ParseException e) {
			}
		}
		return mu;
	}
}
